
import {createRouter, createWebHistory} from 'vue-router'
import MyTest5 from "@/components/test/_6/MyTest5.vue";
import MyTest4 from "@/components/test/_5/MyTest4.vue";
import MyTest3 from "@/components/test/_4/MyTest3.vue";
import MyTest5Child from "@/components/test/_6/MyTest5Child.vue";

const router = createRouter({
    history: createWebHistory(),
    routes: [
        {
            path: '/MyTest5',
            component: MyTest5,
            children: [ // 子路由的页面会在父路由的RouterView上展示
                // {
                //     path: 'Child',
                //     component: MyTest5Child
                // },
                {
                    name: '/MyTest5/Child',
                    path: 'Child/:id/:title/:content', // params占位, 且不能用path进入, 只能用name进入
                    component: MyTest5Child,
                    // 将路由收到的params转为props让路由组件接收
                    // props: true,
                    // 函数写法
                    props(route) {
                        if (Object.keys(route.query).length != 0) { // 判断使用的那种传参
                            return route.query;
                        }
                        return route.params;
                    }
                }
            ]
        },
        {
            path: '/MyTest4',
            component: MyTest4
        },
        {
            path: '/MyTest3',
            component: MyTest3
        },
        // {
        //     path: '/',
        //     redirect: '/MyTest3'
        // } // 设置默认地址, 重定向
    ]
})

export default router;